﻿namespace System.Linq
{
	using System.Collections.Generic;
	using System.IO;

	/// <summary>
	/// Provides a set of extension methods for streams.
	/// </summary>
	public static class StreamExtensions
	{
		/// <summary>
		/// Reads this stream as text, line by line.
		/// </summary>
		/// <param name="stream"></param>
		/// <returns>Returns read text lines.</returns>
		public static IEnumerable<string> AsTextLines(this Stream stream)
		{
			if (stream == null)
				throw new ArgumentNullException("stream");

			using (StreamReader reader = new StreamReader(stream))
			{
				while (!reader.EndOfStream)
					yield return reader.ReadLine();
			}
		}
	}
}
